package com.briup.oagg.model.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.po.LikeTable;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 运行逆向工程配置类，生成数据库对应的类和接口
 * @Author briup
 * @Date 2023/2/3
 */
public class MybatisPlusGenerator {
    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/oagg?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8";
        String username = "root";
        String password = "root";
        String filePath = "D:\\test\\oagg\\oagg-model\\src\\main\\java";//设置包和代码指定输出目录
        String mapperXmlPath = "D:\\test\\oagg\\oagg-model\\src\\main\\resources\\mappers\\basic";
        String parentPackage = "com.briup.oagg.model";//父包名
        List<String> tables = Arrays.asList("oagg_operator_component","oagg_operator_component_config");//需要生成的表名
        String tablePrefix = "oagg"; //去掉表前缀
        FastAutoGenerator.create(url,username,password)
                .globalConfig(builder -> {
                    builder.author("briup")
                            .disableOpenDir() //生成文件后不自动打开所在目录
                            .outputDir(filePath);
                }).packageConfig(builder -> {
                    builder.parent(parentPackage)
                            .controller("web.controller")
                            .entity("bean.basic")
                            .mapper("mapper.basic")
                            .pathInfo(Collections.singletonMap(OutputFile.xml,mapperXmlPath));
                })
                .strategyConfig(builder -> {
                    builder.addInclude(tables)
                            .addTablePrefix(tablePrefix)
                            .controllerBuilder()
                            //.enableFileOverride()
                            .enableRestStyle()
                            .serviceBuilder()
                            //.enableFileOverride()
                            .mapperBuilder().enableBaseColumnList().enableBaseResultMap()
                            //.enableFileOverride()
                            .entityBuilder()
                            //.enableFileOverride()
                            .enableLombok().enableChainModel();
                }).templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
